/*
 * common.h
 *
 *  Created on: Apr 30, 2011
 *      Author: tqlong
 */

#ifndef COMMON_H_
#define COMMON_H_

#include <QtCore/QTextStream>
#include <armadillo>
#include <limits>
#include "../viewer/viewer.h"


#define binary_write(os, var) os.write((char*)&var, sizeof(typeof(var)))
#define binary_read(os, var) os.read((char*)&var, sizeof(typeof(var)))
#define POSITIVE_INFINITY std::numeric_limits<double>::infinity()
#define NEGATIVE_INFINITY -std::numeric_limits<double>::infinity()

namespace common {
  //void loadVVec(const std::string& fName, std::vector<vec>& vvec);
  int loadVVec(const std::string& fName, std::vector<arma::vec>& vvec, const std::string& format);

  template <typename vec>
  double norm(const vec& v, double norm_type)
  {
    return (norm_type == POSITIVE_INFINITY) ?
              arma::norm(v, "inf") :
              arma::norm(v, (int)norm_type);
  }
}

class Log
{
public:
  static QTextStream m_log;
};

#endif /* COMMON_H_ */
